//新零售内循环，同Trait BP/AR/TR/SB
//新零售1开始时间小于等于新零售2结束时间，新零售1开始时间大于新零售2开始时间
//S2<S1<=E2
//新零售1大于新零售2

var result_91_3 = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"", "MSG":"","DATA":"","RULE":"FS_91_3"}');
var JSON_LINKSAVE = !isNull(LINKSAVE) ? JSON.parse(LINKSAVE) : [];

function inPRICE_TRAIT(PRICE_TRAIT) {
    var arr = ['BP', 'AR', 'TR', 'SB'];
    for (var i = 0; i < arr.length; i++) {
        if (PRICE_TRAIT == arr[i]) {
            return true;
        }
    }
    return false;
}

function RisePrice(TRAIT_STORE_NBR, RETAIL_TYPE, JSON_ITEM_LIST) {
    for (var i = 0; i < JSON_ITEM_LIST.length; i++) {
        var S2 = new Date(JSON_ITEM_LIST[i].EFFECTIVE_DATE);
        var E2 = new Date(JSON_ITEM_LIST[i].EXPIRATION_DATE);
        if (TRAIT_STORE_NBR == JSON_ITEM_LIST[i].PRICE_TRAIT
            && inPRICE_TRAIT(JSON_ITEM_LIST[i].PRICE_TYPE)
            && inPRICE_TRAIT(RETAIL_TYPE)
            && betweenDay(S2,EFF_DATE) > 0 && betweenDay(EFF_DATE,E2) >= 0
            && NEW_RETAIL > JSON_ITEM_LIST[i].NEW_RETAIL) {
            return true;
        }
    }
    return false;
}
if(!isNull(UPC_NBR) && UPC_NBR.toString().substr(0, 2) == '21') {
    if (!isNull(LINKSAVE)
        && !inSuspendBP(ITEM_NBR, NEW_RETAIL_EFF_DATE, JSON_ITEM_LIST, ID, RETAIL_TYPE)
        && RisePrice(TRAIT_STORE_NBR, RETAIL_TYPE, JSON_ITEM_LIST)
        && (LinkSaveRisePriceBPSB(JSON_LINKSAVE, RETAIL_TYPE, EFF_DATE, EXP_DATE) || LinkSaveRisePriceARTR(JSON_LINKSAVE, RETAIL_TYPE, EFF_DATE, EXP_DATE))) {
        result_91_3.CODE = 1;
        result_91_3.ACTION = "APPROVAL_LEVEL";
        result_91_3.LEVEL = "AG";
        result_91_3.MSG = "与Linksave冲突的高风险变价，需GMM审批";
    }
}
JSON.stringify(result_91_3);


